package me.sdevil507.org.po;


import lombok.Data;
import lombok.EqualsAndHashCode;
import me.sdevil507.supports.jpa.BaseJpaSnowflakeIdAndAuditEntity;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 机构资源表[OrgResourcePo]
 *
 * @author sdevil507
 * created on 2020-06-23 18:43:30
 */
@Entity
@Table(name = "biz_org_resource")
@Data
@EqualsAndHashCode(callSuper = true)
public class OrgResourcePo extends BaseJpaSnowflakeIdAndAuditEntity {

    /**
     * 名称
     */
    @Column
    private String title;

    /**
     * 资源编码
     */
    @Column
    private String code;

    /**
     * 资源类型
     * <p>
     * 1:菜单
     * 2:按钮
     */
    @Column
    private Integer type;

    /**
     * 资源分类
     * <p>
     * 1:基础
     * 2:增值
     */
    @Column
    private Integer classify;

    /**
     * 同级排序
     */
    @Column
    private Integer sortNum = 1;

    /**
     * 父id
     */
    @Column
    private Long parentId;

    /**
     * 子资源
     */
    @OneToMany(cascade = CascadeType.REMOVE)
    @JoinColumn(name = "parentId", foreignKey = @ForeignKey(name = "none"))
    @OrderBy("sortNum ASC")
    @Where(clause = "type=1")
    private List<OrgResourcePo> children = new ArrayList<>();

    /**
     * 子模块
     */
    @OneToMany(cascade = CascadeType.REMOVE)
    @JoinColumn(name = "parentId", foreignKey = @ForeignKey(name = "none"))
    @OrderBy("sortNum ASC")
    private List<OrgResourcePo> subModules = new ArrayList<>();

}